package com.project.client.service.impl;

import com.project.client.domain.UserEntity;
import com.project.client.mapper.UserMapper;
import com.project.client.service.UserService;
import com.project.common.service.BaseServiceImpl;
import com.project.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 客户端帐号Service业务层处理
 *
 * @author project
 * @date 2021-05-10
 */
@Service
public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserEntity> implements UserService {

    @Override
    public int updatePassword(Long uid, String password) {
        int count = baseDao.updatePassword(uid, SecurityUtils.encryptPassword(password));
        return count;
    }

    @Override
    public UserEntity selectByUsername(String username) {
        return baseDao.selectOne(getQueryWrapper().eq("username", username));
    }

    @Override
    public UserEntity selectById(Long id) {
        return baseDao.selectById(id);
    }

    @Override
    public List<UserEntity> selectList(UserEntity entity) {
        return baseDao.list(entity);
    }

    @Override
    public int save(UserEntity entity) {
        int count = baseDao.insert(entity);
        return count;
    }

    @Override
    public int update(UserEntity entity) {
        int count = baseDao.updateById(entity);
        return count;
    }

    @Override
    public int delete(Long[] ids) {
        int count = baseDao.deleteBatchIds(Arrays.asList(ids));
        return count;
    }
}
